package org.jit.sose.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import org.jit.sose.entity.ArchivesInfo;
import org.jit.sose.entity.TreeNode;
import org.jit.sose.service.IArchivesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class ArchiveController {
    @Autowired
    IArchivesService iArchivesService;

    @RequestMapping(value = "/getAllArchives")
    @ResponseBody
    @CrossOrigin(origins = "*",maxAge = 3600)
    public List getAllArchives(){
        List<ArchivesInfo> archivesInfos = iArchivesService.getAllArchives();
        return archivesInfos;
    }

    @RequestMapping(value = "getArchivesByClassifyId")
    @ResponseBody
    @CrossOrigin(origins = "*",maxAge = 3600)
    public List getArchivesByClassifyId(String classifyId){
        List<ArchivesInfo> archivesInfos = iArchivesService.getArchivesByClassifyId(classifyId);
        return archivesInfos;
    }

    @RequestMapping(value = "addArchive",method = RequestMethod.POST)
    @ResponseBody
    @CrossOrigin(origins = "*",maxAge = 3600)
    public void addArchive(@RequestBody String archive){

        ArchivesInfo archivesInfo = JSON.parseObject(archive,new TypeReference<ArchivesInfo>(){});
        System.out.println("新增档案"+archivesInfo.getArchivesName());
        iArchivesService.insertArchive(archivesInfo);
    }



}
